
{{$svcType := .ServiceType}}
type {{.ServiceType}}GinService interface {
{{- range .MethodMap}}
	{{- if ne .Comment ""}}
	{{.Comment}}
	{{- end}}
	{{.Name}}(context.Context, *{{.Request}}) (*{{.Reply}}, error)
{{- end}}
}


type {{.ServiceType}}GinHandler interface {
    RegisterRouter(r *gin.Engine)
{{- range .MethodMap}}
	{{- if ne .Comment ""}}
	{{.Comment}}
	{{- end}}
	{{.Name}}() gin.HandlerFunc
{{- end}}
}

type gin{{.ServiceType}} struct{
    srv {{.ServiceType}}GinService
}

func New{{.ServiceType}}GinHandler(srv {{.ServiceType}}GinService) {{.ServiceType}}GinHandler{
    return &gin{{.ServiceType}}{
        srv: srv,
    }
}


func (h *gin{{.ServiceType}}) RegisterRouter(r *gin.Engine) {
	{{- range .Methods}}
	r.{{.Method}}("{{.Path}}", h.{{.Name}}())
	{{- end}}
}

{{- range .Methods}}
func (h *gin{{$svcType}}) {{.Name}}() gin.HandlerFunc {
	return func(gtx *gin.Context) {
		var in {{.Request}}
		{{- if eq .ParamType 0}}
		err := gtx.ShouldBindUri(&in)
		{{- else if eq .ParamType 1}}
		err := gtx.ShouldBindQuery(&in)
		{{- else}}
		err := gtx.ShouldBindJSON(&in)
		{{- end}}
		if err != nil{
		    gtx.AbortWithStatusJSON(http.StatusBadRequest, map[string]any{
        		"code":    1,
        		"message": "param binding error",
        		"detail":  err.Error(),
        	})
        	return
		}

		resp, err := h.srv.{{.Name}}(gtx.Request.Context(), &in)
		if err != nil {
			gtx.AbortWithStatusJSON(http.StatusBadRequest, map[string]any{
				"code":    1,
				"message": "param binding error",
				"detail":  err.Error(),
			})
			return
		}

		gtx.JSON(http.StatusOK, map[string]any{
        	"code":    0,
        	"message": "success",
        	"payload": resp,
        })
        return
	}
}
{{- end}}
